<template>
  <view class="home-wrapper">
    <view class="jz-bg-wrapper">
      <view class="item-wrapper box1">
        <image
            class="jz-bg"
            src="https://ai-sbbs.xyz/api/profile/upload/2024/07/01/d397bfe02d37486fb98379e4f12a18be.png"
        />
        <image
            class="img-item"
            mode="scaleToFill"
            src="https://ai-sbbs.xyz/api/profile/upload/2024/10/bazi.png"
            @click="toChat(1)"
        />
      </view>

      <view class="item-wrapper ">
        <image
            class="jz-bg"
            src="https://ai-sbbs.xyz/api/profile/upload/2024/07/01/d397bfe02d37486fb98379e4f12a18be.png"
        />
        <image
            class="img-item img-item-work"
            mode="scaleToFill"
            src="https://ai-sbbs.xyz/api/profile/upload/2024/10/liuyao.png"
            @click="toChat(2)"
        />
      </view>

      <!--      <view class="item-wrapper">-->
      <!--        <image-->
      <!--          class="jz-bg"-->
      <!--          src="https://ai-sbbs.xyz/api/profile/upload/2024/07/01/d397bfe02d37486fb98379e4f12a18be.png"-->
      <!--        />-->

      <!--        <image-->
      <!--          @click="toChat(1)"-->
      <!--          class="img-item img-item-money"-->
      <!--          mode="scaleToFill"-->
      <!--          src="https://ai-sbbs.xyz/api/profile/upload/2024/07/01/abe9cb05a09447b5b16a1d79bfb34ecc.png"-->
      <!--        />-->
      <!--      </view>-->

      <!--      <view class="item-wrapper">-->
      <!--        <image-->
      <!--          class="jz-bg"-->
      <!--          src="https://ai-sbbs.xyz/api/profile/upload/2024/07/01/d397bfe02d37486fb98379e4f12a18be.png"-->
      <!--        />-->

      <!--        <image-->
      <!--          @click="toChat(1)"-->
      <!--          class="img-item img-item-health"-->
      <!--          mode="scaleToFill"-->
      <!--          src="https://ai-sbbs.xyz/api/profile/upload/2024/07/01/3fe8321721d74e6c983d22847b32563c.png"-->
      <!--        />-->
      <!--      </view>-->
    </view>
  </view>
</template>

<script>
import shareSdk from '@/utils/share.js'
import {commonStorage} from "../../utils/common";
import {loginWechatApi} from "../../apis/user";

export default {
  mixins: [shareSdk],
  data() {
    return {
      title: "Hello"
    };
  },
  async onShow() {
    let mobile = commonStorage.getStorageSync("mobile");
    if (!mobile) {
      const userInfo = commonStorage.getStorageSync("userInfo");
      if (userInfo) {
        mobile = JSON.parse(userInfo).mobile || '';
      }
    }
    if (mobile) {
      let {code, data} = await loginWechatApi({
        mobile: mobile
      });
      if (code == 1) {
        commonStorage.setStorage("token", data.token);
        commonStorage.setStorage("userInfo", JSON.stringify(data.userVO));
        const userVO = data.userVO
        if (!userVO.birthDate || !userVO.nickName || !userVO.birthPlace) {
          uni.showToast({
            title: '请先去我的页面完善个人信息',
            icon: 'none'
          })
        }
      }
    }
  },
  onLoad(option) {
  },
  methods: {
    toChat(i) {
      console.log(wx.miniProgram, "##");

      // uni.navigateBack();

      // uni.navigateBack(3);

      // wx.miniProgram.redirectTo({ url: "/pqgeInfo/chat/chat" });
      if (i === 1) {
        uni.navigateTo({
          url: "/pqgeInfo/chat/chat"
        });
      } else if (i === 2) {
        uni.navigateTo({
          url: "/pqgeInfo/chat/chat2"
        });
      }

      // wx.miniProgram.navigateTo({
      //   url: "../pqgeInfo/chat/chat?flag=1",
      //   success: function(res) {
      //     console.log(res, "success");
      //   },
      //   fail: function(res) {
      //     console.log(res, "fail");
      //   }
      // });

      // uni.webView.navigateTo({
      //   url: "/pqgeInfo/chat/chat?flag=1",
      //   success: function(res) {
      //     console.log(res, "success");
      //   },
      //   fail: function(res) {
      //     console.log(res, "fail");
      //   }
      // });
    }
  }
};
</script>

<style lang="scss">
.home-wrapper {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  background-image: url("https://ai-sbbs.xyz/api/profile/upload/2024/07/01/7213aa3997034401af79ea05ebc1d81e.png");
  background-size: cover;
  background-repeat: no-repeat;

  .home-bg {
    position: absolute;
    width: 100%;
    height: 100%;
  }

  .jz-bg-wrapper {
    // margin: 12px;
    // position: relative;
    // height: 156px;
    margin-top: 250px;
    // padding: 32px 37px;
    //display: flex;

    //flex-wrap: wrap;
    .item-wrapper {
      position: relative;
      width: 100%;
      height: 252rpx;
      //width: 375rpx;
      //height: 252rpx;
      margin-top: 40rpx;
      display: flex;
      justify-content: center;
      align-items: center;

      &.box1 {
        margin-top: 160rpx;
      }

      .jz-bg {
        position: absolute;
        top: 0;
        left: 0;
        bottom: 0;
        right: 0;
        width: 100%;
        height: 100%;
      }
    }

    .img-item {
      position: absolute;
      z-index: 2;
      width: 150px;
      height: 90px;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
      //&.img-item-work {
      //  right: 37px;
      //}
      //
      //&.img-item-money {
      //  bottom: 32px;
      //}
      //&.img-item-health {
      //  bottom: 32px;
      //  right: 37px;
      //}
    }
  }
}
</style>

